package com.ymatou.iapi.dglogin.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.common.lang.CipherUtil;
import com.ymatou.iapi.dglogin.parameter.AppSourceEnum;
import com.ymatou.iapi.dglogin.parameter.SellerWxLoginBean;
import com.ymatou.iapi.dglogin.service.SellerWxLoginCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.database.model.DGThirdPartyBindInfo;
import com.ymttest.database.model.DGUserExtInfo;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.model.DGWxUnionidBindInfo;
import com.ymttest.database.mongo.UserTokenWapper;
import com.ymttest.utils.TestDataManager;

import com.ymttest.database.sqlwapper.DGUserWapper;

/**
 * 商家微信登录 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SellerWxLogin {
	private static SellerWxLoginBean SellerWxLoginBean;
	private static SellerWxLoginCall SellerWxLoginCall;
	private static String MCOKURL = "http://headimgurl.com";
	private static Integer UserGender = 1;
	DGUserWapper DGUserWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商家微信登录");
	}

	@Before
	public void caseUp() {
		SellerWxLoginBean = new SellerWxLoginBean();
		SellerWxLoginCall = new SellerWxLoginCall();
		DGUserWapper = new DGUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(SellerWxLoginCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verifyDB(UserCreateBean usercreateBean2, Integer uid) {
		Logger.comment("验证DGUserInfo");
		DGUserInfo uinfo = DGUserWapper.selectDGUserInfo(uid).get(0);
		Logger.verifyEquals(usercreateBean2.getIscs() == null ? false : usercreateBean2.getIscs(), uinfo.getIsCs(), "验证IsCs");
		// loginid随机生成
		Logger.verifyNotNull(uinfo.getLoginId(), "验证LoginId");
		Logger.verifyNotNull(uinfo.getLoginPwd(), "验证LoginPwd");
		Logger.verifyEquals(usercreateBean2.getLogoUrl(), uinfo.getLogoUrl(), "验证LogoUrl");
		if (usercreateBean2.getMobile() != null) {
			Logger.verifyEquals(usercreateBean2.getMobile(), uinfo.getMobile(), "验证Mobile");
		}
		if (usercreateBean2.getMobileAreaCode() != null) {
			Logger.verifyEquals(usercreateBean2.getMobileAreaCode(), uinfo.getMobileAreaCode(), "验证MobileAreaCode");
		}
		if (usercreateBean2.getBelongSellerId() != null) {
			Logger.verifyEquals(usercreateBean2.getBelongSellerId(), uinfo.getBelongSellerId(), "验证BelongSellerId");
		}

		Logger.verifyEquals(usercreateBean2.getNickname(), uinfo.getNickname(), "验证Nickname");
		Logger.verifyEquals(usercreateBean2.getUserGender() == null ? 0 : usercreateBean2.getUserGender(), uinfo.getUserGender(), "验证UserGender");
		Logger.verifyEquals(usercreateBean2.getUserType() == null ? 0 : usercreateBean2.getUserType(), uinfo.getUserType(), "验证UserType");
		Logger.verifyEquals(0, uinfo.getUserStatus(), "验证UserStatus");
		Logger.comment("验证DGUserExtInfo");
		DGUserExtInfo exinfo = DGUserWapper.selectDGUserExtInfo(uid).get(0);
		Logger.verifyEquals(usercreateBean2.getAppSource(), exinfo.getAppSource(), "验证AppSource");
		Logger.verifyEquals(usercreateBean2.getChannelSource() == null ? 0 : usercreateBean2.getChannelSource(), exinfo.getChannelSource(), "验证ChannelSource");
		if (usercreateBean2.getClientIp() != null) {
			Logger.verifyEquals(usercreateBean2.getClientIp(), exinfo.getClientIp(), "验证ClientIp");
		}
		if (usercreateBean2.getCountryCode() != null) {
			Logger.verifyEquals(usercreateBean2.getCountryCode(), exinfo.getCountryCode(), "验证CountryCode");
		}
		// 根据uid和oid生成设备号
		Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getUnionId()), exinfo.getPhysicsDeviceId(), "验证DeviceId");
		Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getOpenId()), exinfo.getLogicDeviceId(), "验证EquipmentId");
		if (usercreateBean2.getInvitationCode() != null) {
			Logger.verifyEquals(usercreateBean2.getInvitationCode(), exinfo.getInvitationCode(), "验证InvitationCode");
		}
		// 现在没有remark
		// if (usercreateBean2.getRemark() != null) {
		// Logger.verifyEquals(usercreateBean2.getRemark(), exinfo.getRemark(),
		// "验证Remark");
		// }
		Logger.verifyEquals(usercreateBean2.getTerminalSource() == null ? 0 : usercreateBean2.getTerminalSource(), exinfo.getTerminalSource(), "验证TerminalSource");
		Logger.comment("验证DGThirdPartyBindInfo");
		DGThirdPartyBindInfo tpinfo = DGUserWapper.selectDGThirdPartyBindInfo(uid).get(0);
		// 多绑定关系在login站点考虑 这里主要看数据落地正确
		Logger.verifyEquals(usercreateBean2.getAppSource(), tpinfo.getAppSource(), "验证AppSource");
		Logger.verifyEquals(usercreateBean2.getOpenId(), tpinfo.getOpenId(), "验证OpenId");
		Logger.verifyEquals(usercreateBean2.getChannelSource() == null ? 0 : usercreateBean2.getChannelSource(), tpinfo.getThirdPartyType(), "验证ThirdPartyType");
		if (usercreateBean2.getUnionId() != null) {
			Logger.verifyEquals(usercreateBean2.getUnionId(), tpinfo.getUnionId(), "验证UnionId");
		}
		Logger.verifyEquals(usercreateBean2.getUserType() == null ? 0 : usercreateBean2.getUserType(), tpinfo.getUserType(), "验证UserType");

		Logger.comment("验证DGWxUnionidBindInfo");
		List<DGWxUnionidBindInfo> wxuinfo = DGUserWapper.selectDGWxUnionidBindInfo(uid);
		if (wxuinfo.size() > 0) {
			Logger.verifyEquals(usercreateBean2.getUserType() == null ? 0 : usercreateBean2.getUserType(), wxuinfo.get(0).getUserType(), "验证UserType");
			Logger.verifyEquals(usercreateBean2.getUnionId(), wxuinfo.get(0).getUnionId(), "验证UnionId");
		}
	}

	/**
	 * @param SellerWxLoginBean2
	 * @param oid
	 * @param uid
	 * @param name
	 * @return
	 */
	private UserCreateBean initUserCreateBean(SellerWxLoginBean SellerWxLoginBean2, String oid, String uid, String name) {
		UserCreateBean usercreateBean2 = new UserCreateBean();
		usercreateBean2.setAppSource(SellerWxLoginBean.getAppSource());
		usercreateBean2.setClientIp(SellerWxLoginBean.getClientIp());
		usercreateBean2.setNickname(name);
		usercreateBean2.setOpenId(oid);
		usercreateBean2.setUnionId(uid);
		usercreateBean2.setWxAppName(SellerWxLoginBean.getWxAppName());
		usercreateBean2.setChannelSource(6);
		usercreateBean2.setLogoUrl(MCOKURL);
		usercreateBean2.setUserGender(UserGender);
		return usercreateBean2;
	}

	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_001() {
		Logger.start(true,"商家微信登录,成功-默认商家");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("true", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals(userid.toString(), SellerWxLoginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(SellerWxLoginCall.getString("accessToken"), "验证accessToken");
			Map<String, Object> token1 = new UserTokenWapper().getUserTokenByUid(userid);
			Logger.comment(token1.toString());
			Logger.verifyEquals(AppSourceEnum.parse(u.getAppSource()).toString().toLowerCase(), token1.get("tSource"), "验证tSource");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_002() {
		Logger.start(true,"商家微信登录,成功-默认客服");
		try {
			UserCreateBean u = DGUserCallService.initCsUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("true", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals(userid.toString(), SellerWxLoginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(SellerWxLoginCall.getString("accessToken"), "验证accessToken");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SellerWxLogin_003() {
		Logger.start(true,"商家微信登录,失败-默认用户");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("false", SellerWxLoginCall.getString("success"), "验证success");
			//errorMessage":"请求用户类型与当前小程序允许的用户类型不一致，wxAppName:wxsqBuyer, allowUserType:0, reqUserType:1"}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_004() {
		Logger.start(true,"商家微信登录,失败-独立用户");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqOther);
			u.setBelongSellerId(DGUserCallService.TestWxsqOtherSellerId);
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("false", SellerWxLoginCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_005() {
		Logger.start(true,"商家微信登录,openid不存,unionid存在成功");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId()+1);
			
			SellerWxLoginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId()+1);
			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("true", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals(userid.toString(), SellerWxLoginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(SellerWxLoginCall.getString("accessToken"), "验证accessToken");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_006() {
		Logger.start(true,"商家微信登录,openid不存,unionid不存在登入失败");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId()+1);
			
			SellerWxLoginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId()+1);
			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId()+1);
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("false", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals("100", SellerWxLoginCall.getString("errorCode"), "验证errorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_007() {
		Logger.start(true,"商家微信登录,openid和wxAppName不匹配失败");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("false", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals("2", SellerWxLoginCall.getString("errorCode"), "验证errorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_008() {
		Logger.start(true,"商家微信登录,不输入wxAppName失败");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
//			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("false", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", SellerWxLoginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_009() {
		Logger.start(true,"商家微信登录,不输入code失败");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
//			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("false", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", SellerWxLoginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_010() {
		Logger.start(true,"商家微信登录,不输入clientIp成功");
		//ip可以不输入
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
//			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("true", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals(userid.toString(), SellerWxLoginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(SellerWxLoginCall.getString("accessToken"), "验证accessToken");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_011() {
		Logger.start(true,"商家微信登录,不输入appsource失败");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
//			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("false", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", SellerWxLoginCall.getString("errorCode"), "验证errorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_012() {
		Logger.start(true,"商家微信登录,成功-默认商家-带deviceid");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			SellerWxLoginBean.setTerminalSource(1);
			SellerWxLoginBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("true", SellerWxLoginCall.getString("success"), "验证success");
			Logger.verifyEquals(userid.toString(), SellerWxLoginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(SellerWxLoginCall.getString("accessToken"), "验证accessToken");
			Map<String, Object> token1 = new UserTokenWapper().getUserTokenByUid(userid);
			Logger.comment(token1.toString());
			Logger.verifyEquals(AppSourceEnum.parse(u.getAppSource()).toString().toLowerCase(), token1.get("tSource"), "验证tSource");
			Logger.verifyEquals(SellerWxLoginBean.getDeviceId(), token1.get("deviceId"), "验证deviceId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxLogin_013() {
		Logger.start(true,"已删除商家微信登录,失败");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			DGUserCallService.DeleteUser(userid);
			SellerWxLoginBean.setClientIp(TestDataManager.getRandomIp());
			SellerWxLoginBean.setCode("abcdefg");
			SellerWxLoginBean.setAppSource(u.getAppSource());
			SellerWxLoginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			SellerWxLoginCall.setData(SellerWxLoginBean);
			SellerWxLoginCall.addHeader("mock", "mock-enable");
			SellerWxLoginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			SellerWxLoginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token=("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			SellerWxLoginCall.addHeader("mockParam-1-token",token);
			SellerWxLoginCall.addHeader("mockParam-1-openId",u.getOpenId());
			
//			SellerWxLoginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
//			SellerWxLoginCall.addHeader("mockParam-2-openId",u.getOpenId());
//			SellerWxLoginCall.addHeader("mockParam-2-unionId",u.getUnionId());
			SellerWxLoginCall.callService();			
			Logger.verifyEquals("false", SellerWxLoginCall.getString("success"), "验证success");
//			Logger.verifyEquals(userid.toString(), SellerWxLoginCall.getString("userId"), "验证userId");
//			Logger.verifyNotNull(SellerWxLoginCall.getString("accessToken"), "验证accessToken");
//			Map<String, Object> token1 = new UserTokenWapper().getUserTokenByUid(userid);
//			Logger.comment(token1.toString());
//			Logger.verifyEquals(AppSourceEnum.parse(u.getAppSource()).toString().toLowerCase(), token1.get("tSource"), "验证tSource");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}